'use strict';

angular.module('com.dcos.app').controller('UserCenterController', function($window,$scope,$state, $filter, api, $uibModal,dialog,UserCenterService) {
  var vm = this;
  vm.breadCrumbArr = [api.breadCrumbMap.usercenter.root];
  vm.initPageSize = api.initPageSize;

  vm.msg="删除操作不可恢复，确定要删除？";

  vm.userid=$window.sessionStorage.getItem("curUserId");
  vm.dept_id=$window.sessionStorage.getItem("curDept_Id");
  vm.usertype=$window.sessionStorage.getItem("curUserType");

  // if(!vm.userid)
  //   $state.go('login');

  vm.getUserList = function() {
    vm.loading = false;
    
    UserCenterService.getlist(vm.usertype,vm.dept_id).then(function (response) {
      if(response.data.list!=null)
        vm.userData=response.data.list;
      else
        vm.userData=[];
      vm.page = 1;

      vm.pageSize = vm.initPageSize;
      vm.totalCount = vm.userData.length;
      vm.itemLength = vm.totalCount;
      vm.reverse = false;
    });
  }
  vm.getUserList();

  //创建
  vm.create = function()
  {
    var modalInstance = $uibModal.open({
      animation: true,
      templateUrl: 'controllers/usercenter/detail/detail.html',
      controller: 'UserCenterDetailController as vm',
      resolve: {
        type:function(){return "create";},
        user:function(){return "";},
        reload:function(){return vm.getUserList;}
      }
    });
  }
  vm.updateStatus = function (user,status) {
    user.status=status;
    UserCenterService.update(user).then(function (response) {
      vm.getUserList();
    });
  }
  vm.edit = function(user) {
    var modalInstance = $uibModal.open({
      animation: true,
      templateUrl: 'controllers/usercenter/detail/detail.html',
      controller: 'UserCenterDetailController as vm',
      resolve: {
        type:function(){return "edit";},
        user:function(){return user;},
        reload:function(){return vm.getUserList;}
      }
    });
  }

  $scope.ok = function(config_id) {
    ConfigService.delete(config_id).then(function (response) {
      vm.getConfigList();
    });
  }
});

